package dom.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.PreparedStatement;
import dom.bean.User;
import dom.util.Connections;
public class UserDao{

	public static User findByCodeAndPass(String stuCode, String password) {
		 Connection connection=Connections.getConnection();
		 PreparedStatement preparedStatement=null;
		 ResultSet rs=null;
		 String SQL="select * from manager where id=? and password=?";
	     try {
			preparedStatement =(PreparedStatement) connection.prepareStatement(SQL);
			//执行
			preparedStatement.setInt(1,Integer.parseInt(stuCode));
			preparedStatement.setString(2,password);
			rs= preparedStatement.executeQuery();
			
			while(rs.next()){

				User user=new User();
//				user.setDomiCode(rs.getString("domi_Code"));
//				user.setPassWord(rs.getString("psw"));
//				user.setName(rs.getString("name"));
//				user.setDomiBuild(rs.getInt("domi_Build"));
//				user.setSex(rs.getString("sex"));
//				user.setStuCode(rs.getString("stu_code"));
//				user.setTel(rs.getString("tel"));
//				user.setEmail(rs.getString("email"));
//				user.setRoleId(rs.getInt("role_id"));
				user.setRoleId(0);
				user.setName(rs.getString("name"));
				user.setStuCode(rs.getInt("id"));
				user.setPassWord(rs.getString("password"));

				rs.close();
				preparedStatement.close();
				connection.close();
	
				return user;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	     

	}
	
}
